namespace QLGT_2.Models
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class QLGTContext : DbContext
    {
        public QLGTContext()
            : base("name=QLGTContext")
        {
        }

        public virtual DbSet<sysdiagram> sysdiagrams { get; set; }
        public virtual DbSet<tbl_ChucNang> tbl_ChucNangs { get; set; }
        public virtual DbSet<tbl_ChucNang_Quyen> tbl_ChucNang_Quyens { get; set; }
        public virtual DbSet<tbl_ChucVu> tbl_ChucVus { get; set; }
        public virtual DbSet<tbl_DaoTao> tbl_DaoTaos { get; set; }
        public virtual DbSet<tbl_GiaoTrinh> tbl_GiaoTrinhs { get; set; }
        public virtual DbSet<tbl_GiaoTrinh_HeDT> tbl_GiaoTrinh_HeDTs { get; set; }
        public virtual DbSet<tbl_GiaoTrinh_Nam> tbl_GiaoTrinh_Nams { get; set; }
        public virtual DbSet<tbl_HeDaoTao> tbl_HeDaoTaos { get; set; }
        public virtual DbSet<tbl_HocHam> tbl_HocHams { get; set; }
        public virtual DbSet<tbl_HocVi> tbl_HocVis { get; set; }
        public virtual DbSet<tbl_Khoa> tbl_Khoas { get; set; }
        public virtual DbSet<tbl_MonHoc> tbl_MonHocs { get; set; }
        public virtual DbSet<tbl_Nganh> tbl_Nganhs { get; set; }
        public virtual DbSet<tbl_NguoiDung> tbl_NguoiDungs { get; set; }
        public virtual DbSet<tbl_NhaXuatBan> tbl_NhaXuatBans { get; set; }
        public virtual DbSet<tbl_Quyen> tbl_Quyens { get; set; }
        public virtual DbSet<tbl_SachBan> tbl_SachBans { get; set; }
        public virtual DbSet<tbl_SachDat> tbl_SachDats { get; set; }
        public virtual DbSet<tbl_TacGia> tbl_TacGias { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<tbl_ChucNang>()
                .HasMany(e => e.tbl_ChucNang_Quyens)
                .WithRequired(e => e.tbl_ChucNang)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_DaoTao>()
                .Property(e => e.MaNganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_GiaoTrinh_HeDTs)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_GiaoTrinh_Nams)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh>()
                .HasMany(e => e.tbl_SachBans)
                .WithRequired(e => e.tbl_GiaoTrinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_GiaoTrinh_HeDT>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh_Nam>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_GiaoTrinh_Nam>()
                .Property(e => e.Nam)
                .IsFixedLength();

            modelBuilder.Entity<tbl_HeDaoTao>()
                .HasMany(e => e.tbl_GiaoTrinh_HeDTs)
                .WithRequired(e => e.tbl_HeDaoTao)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Khoa>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Khoa>()
                .Property(e => e.Khoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Khoa>()
                .HasMany(e => e.tbl_MonHocs)
                .WithRequired(e => e.tbl_Khoa)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_MonHoc>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_MonHoc>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_MonHoc>()
                .HasMany(e => e.tbl_DaoTaos)
                .WithRequired(e => e.tbl_MonHoc)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_MonHoc>()
                .HasMany(e => e.tbl_GiaoTrinh_Nams)
                .WithRequired(e => e.tbl_MonHoc)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Nganh>()
                .Property(e => e.MaNganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Nganh>()
                .Property(e => e.Nganh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_Nganh>()
                .HasMany(e => e.tbl_DaoTaos)
                .WithRequired(e => e.tbl_Nganh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.TenDangNhap)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.MatKhau)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.Email)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NguoiDung>()
                .Property(e => e.RandomPass)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.SoDT)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.Fax)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .Property(e => e.Email)
                .IsFixedLength();

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .HasMany(e => e.tbl_GiaoTrinhs)
                .WithRequired(e => e.tbl_NhaXuatBan)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_NhaXuatBan>()
                .HasMany(e => e.tbl_SachDats)
                .WithRequired(e => e.tbl_NhaXuatBan)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Quyen>()
                .HasMany(e => e.tbl_ChucNang_Quyens)
                .WithRequired(e => e.tbl_Quyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_Quyen>()
                .HasMany(e => e.tbl_NguoiDungs)
                .WithRequired(e => e.tbl_Quyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<tbl_SachBan>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_SachBan>()
                .Property(e => e.MaKhoa)
                .IsFixedLength();

            modelBuilder.Entity<tbl_SachDat>()
                .Property(e => e.MaGiaoTrinh)
                .IsFixedLength();

            modelBuilder.Entity<tbl_TacGia>()
                .HasMany(e => e.tbl_GiaoTrinhs)
                .WithRequired(e => e.tbl_TacGia)
                .WillCascadeOnDelete(false);
        }
    }
}
